var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list:"",
  },

  formSubmit: function (e) {
    let name = e.detail.value.name;
    let email = e.detail.value.email;
    let remark = e.detail.value.remark;
    let msg = e.detail.value.msg;
    let that = this;
    app.getUserToken(function (err, token) {
      wx.request({
        url: app.globalData.url +'/index.php?_m=shop/message/ask&v=v20190909b',
        data: { name: name, email: email, remark: remark, msg: msg, auth_token: token },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'post',
        success: (res) => {
          if (res.data.status == 401) {
            // 清空授权token
            app.globalData.token = null
            wx.removeStorageSync('token')
            that.getCustomeItem();
          } else if (res.data.code == 0) {
            wx.showToast({
              title: '填写成功',
              icon: 'success',
              duration: 2000
            });
            setTimeout(function () {
              wx.reLaunch({
                url: '../personal/personal'
              })
            }, 2000)

          }
        }
      })
    })


  },

  getCustomeItem: function () {
    var that = this;
    app.getUserToken(function (err, token) {
      wx.request({
        url: app.globalData.url +'/index.php?_m=shop/customers/get_item',
        data: { auth_token: token },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'post',
        success: (res) => {
          if (res.data.status == 401) {
            // 清空授权token
            app.globalData.token = null
            wx.removeStorageSync('token')
            that.getCustomeItem();
          } else if (res.data.code == 0) {
            that.setData({
              list: res.data.data.item
            })
          }
        }
      })
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCustomeItem();

  },
  onShareAppMessage: function () {
    app.globalData.uid = app.globalData.uid || wx.getStorageSync('uid') || 0;
    return {
      title: '深圳智汇创想科技有限责任公司员工福利购!',
      path: '/pages/index/index?fid=' + app.globalData.uid
    }
  }
})